package tech.aistar.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import tech.aistar.entity.Post;
import tech.aistar.entity.UserLogin;
import tech.aistar.service.IPostService;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.Date;

/**
 * Created by Administrator on 2019/10/5.
 */
@Controller
@RequestMapping("/postP")
public class PostController {
    @Autowired
    private IPostService postService;

    @RequestMapping("/postSave")
    @ResponseBody
    public String addPost(Integer themeId, Integer classId, String postContent, Integer userId, String title,
                          HttpServletRequest req){

        HttpSession ss=req.getSession();
        UserLogin user= (UserLogin) ss.getAttribute("user");
        if(null==user){
            return "未登录";
        }else{
//            System.err.println(postContent+"hhhhhhhhhhhhhhhhhhhhhhhhhhhh");
            Post post = new Post();
            post.setThemeId(themeId);
            post.setClassId(classId);
            post.setPostContent(postContent);
            post.setUserId(1);
            post.setStatus(0);
            post.setTitle(title);
            post.setPtime(new Date());
            post.setPointNum(10);
            postService.savePost(post);
            return "发送成功";
        }
    }
}
